package com.water.tool;

import java.io.FileOutputStream;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;

/**
 * Xml文件操作类
 * 
 * @author whl
 * 
 */
public class XmlUtil {

	/**
	 * 由字符串生成xml
	 * 
	 * @param xmlText
	 */
	public static void createXMLFile(String xmlText, String path) {
		try {
			OutputFormat format = OutputFormat.createPrettyPrint();
			format.setEncoding("UTF-8");
			XMLWriter xmlWriter = new XMLWriter(new FileOutputStream(path),
					format);
			Document doc = DocumentHelper.parseText(xmlText);
			xmlWriter.write(doc);
			xmlWriter.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
